/**
 *  Copyright 2013 Mike Reed
 *
 *  COMP 590 -- Fall 2013
 */

#ifndef GColor_DEFINED
#define GColor_DEFINED

#include "GTypes.h"
#include <algorithm>

/**
 *  Holds a nonpremultiplied color, with each component
 *  normalized to [0...1].
 */
class GColor {
private:
	// called on creation, clamps the 
	void ClampToRange(float min, float max);

public:
    float   fA, fR, fG, fB;

    static GColor Make(float a, float r, float g, float b) {
        GColor c = { a, r, g, b };
        c.ClampToRange(0.0f, 1.0f);
        return c;
    }
};

inline void GColor::ClampToRange(float min, float max){
 	fA = std::min(std::max(min, fA), max); 
    fR = std::min(std::max(min, fR), max);
    fG = std::min(std::max(min, fG), max);
    fB = std::min(std::max(min, fB), max);
 }

static inline void GColor_Print(const GColor& c, char* name){
    printf("Color '%s': {%f, %f, %f, %f}\n", name, c.fA, c.fR, c.fG, c.fB);
}

#endif
